/*
 * @: 
 * @Version: 1.0
 * @Autor: ziwei
 * @Date: 2021-11-16 10:32:52
 * @LastEditors: ziwei
 * @LastEditTime: 2021-11-16 13:57:22
 */
var romanToInt = function(s) {
  let arr = new Map();
  arr.set('I',1)
  arr.set('V',5)
  arr.set('X',10)
  arr.set('L',50)
  arr.set('C',100)
  arr.set('D',500)
  arr.set('M',1000)
  let length = s.length
  let ans = 0;
  for(let i = 0;i<length;i++){
      let value = arr.get(s[i])
      console.log("value",value);
      if(value&&value<arr.get(s[i+1])){
          ans -= value
      }else{
          ans += value
      }
  }
  return ans
};

console.log(romanToInt('III'))